//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package 力扣.题库.滑动窗口.变长滑动窗口.越长约合法;

import java.util.HashMap;

public class demo_1358 {
    public demo_1358() {
    }

    public int numberOfSubstrings(String s) {
        char[] chars = s.toCharArray();
        int n = chars.length;
        int k = 3;
        int left = 0;
        int count = 0;
        HashMap<Character, Integer> map = new HashMap(k);

        for(int i = 0; i < n; ++i) {
            char c = chars[i];
            map.put(c, (Integer)map.getOrDefault(c, 0) + 1);
            if ((Integer)map.get(c) == 0) {
                map.remove(c);
            }

            if (i >= k - 1) {
                for(; map.size() == k; ++left) {
                    char leftC = chars[left];
                    map.put(leftC, (Integer)map.getOrDefault(leftC, 0) - 1);
                    if ((Integer)map.get(leftC) == 0) {
                        map.remove(leftC);
                    }
                }

                count += left;
            }
        }

        return count;
    }
}
